<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>复粉图文库</title>
    <style>
        .img_new{width: 50px;height: 50px;cursor: pointer;}
    </style>
</head>
<body>
<div class="box">
    <section class="content-header">
        <ol class="breadcrumb">
            <li><a><i class="fa fa-dashboard"></i> 复粉管理</a></li>
            <li class="active">复粉图文库</li>
        </ol>
    </section>
    <!-- /.box-header -->
    <section class="content">
        <div class="box-body">
            <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                <div class="row">
                    <div class="col-sm-12">
                        <div id="example1_filter" class="dataTables_length">
                            <label>
                                <input type="search" id="keyword" class="form-control input-sm" placeholder="标题" aria-controls="example1">
                            </label>
                            <button type="button" onclick="search()" class="btn margin" style="background: #18bc9c;color: #ffffff;">搜索</button>
                            <button type="button" onclick="relist()" class="btn margin  bg-aqua" title="刷新"><i class="fa fa-refresh"></i></button>
                            <button type="button" onclick="toadd()"  class="btn margin" style="background: #18bc9c;color: #ffffff;">添加</button>
                            <button type="button" onclick="todel()"  class="btn margin bg-red"><i class="fa  fa-trash-o"></i> 删除</button>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                            <thead>
                            <tr role="row">
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 60px;">
                                    <input id="allchecked" type="checkbox" style="margin-left: 10px">
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 600px;">图片标题</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">图片预览</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px;">总分类</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px;">子分类</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px;">账号池</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">优先级</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">是否指定</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">图文位置</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 200px">创建时间</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">操作</th>
                            </tr>
                            </thead>
                            <tbody id="tb">
                            </tbody>
                        </table>
                        <div class="layui-row pull-right" id="footpager" align="center"></div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    var _keyword = '';
    var _page='1';
    var _size='10'
    $(function(){
        getlist(_keyword);
        //反选
        $('#allchecked').click(function(){
            $("[name = checkboxed]:checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        });
        $('#tb').on('click','.img_new',function () {
            var $_this = $(this);
            var _url = $_this.attr('src');
            window.open(_url);
        });
    })
    function getlist(_keyword)
    {
        $.ajax({
            type: 'post', cache: false,
            url:'{:url("admin/Replyfans/getImgTextList")}',
            data: {keyword:_keyword,page:_page,size:_size},
            success: function(data) {
                if(data.code=="0")
                {
                    $("#tb tr").remove();
                    $.each(data.info,function(index,item){
                        var html='<tr role="row" class="odd" id="tr_'+item.id+'">';
                        html+='<td style="vertical-align: middle;"><input name="checkboxed" value="'+item.id+'" type="checkbox" style="margin-left: 10px"></td>';
                        html+='<td style="vertical-align: middle;">'+item.title+'</td>';
                        html+='<td style="vertical-align: middle;"><img class="margin img_new" src="'+item.imgurl+'"></td>';
                        html+='<td style="vertical-align: middle;">'+item.sumname+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.childname+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.poolname+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.priority+'</td>';
                        if(item.img_local=="")
                            html+='<td style="vertical-align: middle;"><span style="color: #18bc9c;">未指定</span></td>';
                        else
                            html+='<td style="vertical-align: middle;"><span style="color: #18bc9c;">指定</span></td>';
                        html+='<td style="vertical-align: middle;">'+item.img_local+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.createtime+'</td>';
                        html+='<td style="vertical-align: middle;text-align: center">';
                        html+='<div class="btn-group">';
                        html+=' <button onclick="toedit('+item.id+')" type="button" class="btn" style="background: #18bc9c;color: #ffffff;"><i class="fa fa-edit"></i></button>';
                        html+='</div>';
                        html+='</td>';
                        html+='</tr>';
                        $("#tb").append(html);
                    });
                    table = $('#example1').DataTable({
                        "paging": false,
                        "searching": false,
                        "lengthChange":false,
                        "info": false,
                        "autoWidth": false,
                    });
                    layerPager(_page,_size,data.count,"footpager","footpagerbind");
                }
            },
            error: function() {
                alert("发生系统错误,请与管理员联系！");
            }
        });
    }
    function footpagerbind(cpage)
    {
        _page=cpage;
        table.destroy();
        getlist();
    }
    //搜索
    function search()
    {
        table.destroy();
        var keyword = $('#keyword').val();
        getlist(keyword);
    }
    //编辑账号
    function toedit(_id) {
        url = "{:url('replyfans/editImgText')}" + "?aid=" + _id;
        layerWindow('编辑图文',url,'50%','80%');
    }
    //添加
    function toadd() {
        url = "{:url('replyfans/addImgText')}";
        layerWindow('添加图文',url,'60%','80%');
    }
    //删除账号
    function todel() {
        layerConfirm('确认删除',function () {
            var check_val = [];
            $('input[name="checkboxed"]:checked').each(function(){
                check_val.push($(this).val());
            });
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Replyfans/delImgText")}',
                data: {aid: check_val},
                success: function (data) {
                    if(data.code == '0'){
                        layerAlert(data.msg,function(){
                            relist();
                        });
                    }else{
                        layerAlert(data.msg);
                    }
                }
            });
        });
    }
    function relist()
    {
        table.destroy();
        getlist(_keyword);
    }
</script>
</html>